<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <title>Book Manage System </title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <style>
        nav {
            font-size: 1.5rem;
            background-color: #21D4FD;
            background-image: -webkit-linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
            background-image: -moz-linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
            background-image: -o-linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
            background-image: linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
        }

        h1 {
            font-size: 2rem;
            color: white;
        }

        li {
            margin: 10px 20px;
        }

        #searchBox {
            width: 300px;
            float: right;
        }

        #messageIfNone {
            margin-top: 30px;
            color: #007bff;

            text-align: center;
        }
        #messageIfFull {
            margin-top: 30px;
            color: #007bff;

            text-align: center;
        }

    </style>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-primary navbar-dark">
    <ul class="navbar-nav">
        <li>
            <h1><a th:href="@{/}" style="color: white; text-decoration: none">Book Manage System </a></h1>
        </li>
        <li class="nav-item">
            <a class="nav-link" th:href="@{/user/book/getAll}">Book List </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" th:href="@{/user/record/getOwnRecord}">Borrow Record</a>
        </li>
        <li class="nav-item">
            <a class="nav-link active" th:href="@{/user/reserve/getAll}">Reserve Record</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" th:href="@{/user/history/getAll}">history record</a>
        </li>
    </ul>
    <div class="text-white" style="font-size: medium; position: absolute; bottom: 30px; right: 40px">
        <div class="dropdown">
            <a class="dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true"
               aria-expanded="false"
               th:text="${session.name}+', Hello'">
            </a>
            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                <a class="dropdown-item" th:href="@{/user/toInfoPage}" sec:authorize="hasRole('USER')">Person
                    Information</a>
                <a class="dropdown-item" th:href="@{/toChPwdPage}">Modify Password</a>
                <a class="dropdown-item" th:href="@{/logout}">Logout</a>
            </div>
        </div>
    </div>
</nav>

<div class="modal fade" id="reserveModel" data-show="true" aria-labelledby="staticBackdropLabel" aria-hidden="true"
     tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="staticBackdropLabel">Borrow Books Soon</h5>
            </div>
            <div class="modal-body">
                <div>you need to borrow the books in 4 hours</div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="fineModel" data-show="true" aria-labelledby="staticBackdropLabel1" aria-hidden="true"
     tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="staticBackdropLabel1">Fined!</h5>
            </div>
            <div class="modal-body">
                <div>you have to pay the fine if you want to borrow books</div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>


<div class="container" style="margin-top: 40px">
    <table class="table table-hover" style="margin-top: 20px">
        <thead>
        <tr>
            <th>BookId</th>
            <th>ISBN</th>
            <th>BookName</th>
            <th>ReserveTime</th>
            <th>barcode</th>
            <th></th>
            <th></th>
            <th></th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="book: ${ReserveBooks}">
            <!--/*@thymesVar id="getBook_name" type="com.xkx.bookmanager.pojo.Book"*/-->
            <td th:text="${book.getBookId()}"></td>
            <td th:text="${book.getIsbn()}"></td>
            <td th:text="${book.getBookName()}"></td>
            <td th:text="${book.getReserveTime()}"></td>
            <td>
                <img th:src="@{${book.getBarcode()}}">
            </td>
            <td>
            <td><a th:href="@{'/user/reserve/delete/' + ${book.getBookId()}}" class="btn btn-outline-info">Delete</a></td>
            </td>
        </tr>
        </tbody>
    </table>

</div>

<div>
    <a th:if="${reserveNum} ne '0' and ${isFull} eq 0 and ${isFined} eq 0" th:href="@{/user/book/borrow}" class="btn btn-outline-secondary btn-lg" style="margin-left: 40px">Borrow</a>
</div>

<div th:if="${reserveNum} eq '0' " style="width: 100%">
    <h1 id="messageIfNone">you have not reserved a book</h1>
</div>

<div th:if="${isFull} eq '1' " style="width: 100%">
    <h1 id="messageIfFull">you only can borrow 5 books</h1>
</div>
<!--<script th:inline="javascript">-->
<!--    let a = [[${recording}]];-->
<!--    window.onload = function () {-->

<!--        if(a>=5){-->
<!--            $('#alterModel').modal('show')-->
<!--        }-->
<!--        else if(a==1){-->
<!--            console.log(a);-->
<!--        }-->


<!--    }-->

<!--</script>-->

<script th:inline="javascript">
    window.onload = function () {
        if([[${reserveNum}]] !== 0 ) {
            $('#reserveModel').modal('show')
        }

        if([[${isFined}]] == 1){
            $('#fineModel').modal('show')
        }

    }
</script>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>
</html>